package com.baizhi.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * json字符串转换类
 */
public class ObjectMapperTools {

    /**
     * 创建ObjectMapper对象
     */
    private static ObjectMapper objectMapper = null;

    /*在静态代码块下，objectMapper只会创建一次*/
    static {
        objectMapper = new ObjectMapper();

        /*如果是空对象的时候,不抛异常(如果使用了mybatis懒加载必须设置)*/
        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
    }

    /**
     * 获取ObjectMapper对象
     * @return ObjectMapper对象
     */
    public static ObjectMapper getObjectMapper(){
        return objectMapper;
    }

}
